package com.briup.mt.web.controller;

import com.baidu.aip.bodyanalysis.AipBodyAnalysis;
import com.briup.mt.ai.AipPresonClient;
import com.briup.mt.ai.AipPresonClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * @program:
 * @description: 智能识别接口
 * @author: jacky
 * @create: 2020-10-11 15:51
 **/
@Api(description = "人体识别相关接口")
@Validated
@RestController
@RequestMapping("/PersonRecognition")
public class RecognitionPersonController {
	
	@ApiOperation(value = "人体识别")
	@PostMapping("person")
	public void plant( @RequestParam("file") MultipartFile file, HttpServletRequest req, HttpServletResponse resp) throws Exception {
		// 获取人体识别客户端
		AipBodyAnalysis client = AipPresonClient.getInstance();
		// 传入可选参数调用接口
		HashMap<String, String> options = new HashMap<String, String>();
		options.put("type", "gender,age,smoke,orientation,face_mask,is_human");
//		JSONObject res = client.plantDetect(file.getBytes(), new HashMap<>());
		JSONObject res = client.bodyAttr(file.getBytes(), options);
		// 手动返回json
		resp.setHeader("Content-Type", "PersonRecognition/json;charset=UTF-8");
		resp.getWriter().write(res.toString());
	}
}
